var mongoose = require('mongoose'); //引用mongoose模块
var config = require('../config').mongodb;

var models = require('./models');
for(var i in models) require('./' + models[i]);

// 创建一个数据库连接
// mongodb://user:pass@localhost:port/database
var db = mongoose.connect('mongodb://' + config.db_host + '/' + config.db_name);

db.connection.on('error', function(err) {
    console.error('MongoDB Error: %s', err);
    process.exit(1);
});

module.exports = db;